The objects in a Frontier Object Database table can be referenced by their relative positions in the table. This approach permits you to deal with a Frontier table exactly like an array in other programming languages. The first entry in the table can be addressed as:table.name[1]
All other entries are similarly addressed. The 12th item is addressable as:
table.name[12]
Let's look at an example. Go to the Examples table and sort by Kind (click on the "Kind" label at the top of the table so that it is underlined). Open the Quick Script window, type and run the following:
examples[1]
Assuming the first entry in your Examples table is "nextchar" with a value "M", that's what you'll see in the result portion of Quick Script. Try a few more if you like.
Other than manually opening tables and sub-tables until you find an object, you can locate a Frontier object in two ways. We've seen these before, but it won't hurt to point them out again since finding things in Frontier is something you will probably use often.The fastest way to locate an object in Frontier is with the Jump command from the UserLand menu, also accessible by Command-J from the keyboard. This command brings up a dialog into which you type the name of the object you are looking for. If the object exists in Frontier and you've supplied its correct name (including the complete path relative to any table listed in the paths table), you'll be taken directly to it. If the object is a scalar, its entry will be selected. If it's a complex object with its own editing window, that window will be opened. If Frontier can't find the object, it beeps.
If you are looking at some information in a script (or any other object), you can hold down the Command key and double-click on any Frontier term (object database address) and be taken directly to its definition (location) if it can be found. This technique is often the quickest way to navigate from a script to another script it calls.
Frontier includes built-in find-and-replace capability (see Chapter 7 for details). You can use this feature to locate any piece of information you want to find in the Object Database -- though it may take some time.How much of the Object Database is searched for your term? That depends on what window is frontmost when you invoke the operation. Table 6-1 summarizes the scope of the Find & Replace operation.
Table 6-1. Find and Replace
Find & Replace Invoked In... Has Scope Of... ---------------------------- ----------------------------------------- Main Window Entire Object Database Table Window That table and all of its sub-tables, and so on until last sub-table is searched Menubar Window That window plus all of its scripts Outline, Script or That window Word Processing Window -----------------------------------------------------------------------
You can create new entries in the Object Database in several different ways. The manual method for doing so was described in Chapter 2.From the Quick Script window, you create a new variable in the Object Database simply by assigning it a value. For example, scratchpad.y does not exist when you receive Frontier from UserLand Software. But if you type this line into the Quick Script window, you can then examine the scratchpad table and confirm that it has an entry called y with a value of 13.04 and a type of double (floating point):
scratchpad.y = 13.04
Assignment only works for scalars (simple values). Objects that have their own editing window can be created with the "new" verb, e.g.
new(outlineType, @scratchpad.something)
In both cases, all tables included in the full name must exist. If you are curious, lookup the verb table.surePath; it may come in handy one day.
When you create local variables in your scripts, the variables only last as long as the script is running, they are not stored as a permanent part of the Object Database. As noted in Chapter 3, Frontier creates a temporary series of tables representing a dynamic "stack" while the script is running. When you are debugging a script, this location is accessible through the Object Database structure at location system.compiler.stack.
You can export any Frontier object to the desktop for import to another copy of Frontier or back into your original Frontier root file.The relevant UserLand menu options are discussed in Chapter 7. When you export an object using one of the options from the "Export an Object..." item on the UserLand menu, Frontier saves it in the folder you indicate, with the name you provide. In the process, Frontier assigns it the appropriate creator and file type to be recognized by any copy of Frontier.
Desktop scripts, discussed in Chapter 9, are exported in a similar way to other objects, but are stored in a special format on the disk. When they are double-clicked by the user, they are executed rather than being imported into Frontier. (They still require Frontier; in fact, they are temporarily loaded into the root file, executed, then purged.)
You can also copy Frontier objects and paste them into other applications via the Clipboard, just as you are used to doing with other Macintosh applications. You can select text from a word processing text object, and paste it into a document in another application. You can do the same with individual headings of Frontier outline objects, with scalars, and with individual names of table entries.
There is also a more powerful way to copy Frontier objects. In a table window, you can select an outline or word processing text object's entry and, without opening, it, choose the "Copy" or "Cut" option from Frontier's Edit menu. Now when you move to another application, you can paste the entire document or outline - including outline indentation (but not the item markers in an outline). In the process of such data transfer, you lose formatting such as bold text, fonts, and margins, just as when you copy text from any word processor into another application.
This Clipboard approach to moving information from Frontier to other applications extends to tables. You can select a sub-table's entry in a table window, copy it, and paste it into another application document. If you do so, you'll find that the table objects are copied over as a single block of text, but each table entry is labeled with its Frontier name and datatype.
You can import Frontier objects into any Frontier.root file. If the object was exported from Frontier to a file using the "Export an Object..." option from the UserLand menu, you can import it into a Frontier.root file one of two ways:If the object you wish to import into Frontier is a desktop script, you can hold down the Command key when you double-click its icon in the Finder and continue to hold the Command key down until the script's editing window opens in Frontier. You can then save the root file and the desktop script will be saved in the system.deskscripts table with the name of the script as it appears in the script's header.
- double-clicking on it in the Finder, with or without Frontier running (Frontier will be launched if it is not running)
- from within Frontier, choosing "Open..." from the File menu and then choosing the file
Using the Clipboard, you can bring text information from other applications into Frontier. Select some text in an application window, copy it, then switch to Frontier. Paste the text. The outcome of this process depends on what kind of window is frontmost, as shown in Table 6-2.
Table 6-2. Pasting Text into Frontier from Clipboard Depends on the Frontmost Window Type
Table: Text is pasted into new string object named "pasted text"
Word Processing Text: Replaces selection, if any, or is inserted at insertion point if no selection
Outline: In text mode (no heading selected), behavior is same as for Word Processing Text objects. Otherwise, pasted text is inserted into the outline with carriage returns and tabs working as you would expect. The only exception is that if any single line of text exceeds 255 characters in length, it is broken into multiple segments of 255 characters each and segments become headings at the same level as the selected heading and immediately below one another.
Aside from its value and importance in scripting, the Frontier Object Database is a powerful construct in its own right. Because it can search in the text of any item, it may be convenient storing notes to yourself, electronic mail messages, organized outlines of electronic mail accounts, records of users on a local area network, outlines of projects, reminders about appointments, and a host of other items that may or may not be related to a UserTalk script.Contents Page | Previous Section | Next Chapter -- The Frontier EnvironmentFeel free to make extensive use of the database for such things. We recommend that you use your people.XXX table (where "XXX," of course, stands for your initials) as the storage starting point. You can build sub-tables, word processing text entries, and a host of other database entities in this table.
The only limit on what you can use this database for is your imagination.